package cn.yunhe.action;

import java.util.ArrayList;
import java.util.List;

import cn.yunhe.model.House;
import cn.yunhe.services.HouseServices;
import cn.yunhe.util.BaseAction;
import cn.yunhe.util.PageUtil;

/**
 * 
 * @author Administrator
 *
 */
public class HouseAction extends BaseAction {

	private int currPage;
	private int totalPage;
	private List houseList = new ArrayList();
	private HouseServices hs = new HouseServices();

	@Override
	public String execute() throws Exception {
		// 获得页数
		String pageIndex = getRequest().getParameter("pageIndex");
		if (pageIndex != null && !"".equals(pageIndex)) {
			currPage = Integer.parseInt(pageIndex);
		}
		// 获得数据总数
		int houseCount = hs.getHouseCount();
		// 获得总页数
		totalPage = PageUtil.pageCount(houseCount, House.pageCount);
		// 处理首尾页
		if (currPage < 1) {
			currPage = 1;
		}else if(currPage > totalPage){
			currPage = totalPage;
		}
		houseList = hs.getAllHouse(currPage, House.pageCount);
		System.out.println(houseList.size());
		return SUCCESS;
	}
	
	public List getHouseList() {
		return houseList;
	}

	public void setHouseList(List houseList) {
		this.houseList = houseList;
	}

	public HouseServices getHs() {
		return hs;
	}

	public void setHs(HouseServices hs) {
		this.hs = hs;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

}
